//# sourceURL=http://uMapApp/Module/Bench/Bench
define([
    "mhjs/mhjs"
    , "uMap/uMap"
    , "uEarth/uEarth"
    , "../../UI/Layer"
    , "../../Earth/ViewPort"
    , "../StakeNum/StakeNum"
], function (
    mhjs,
    uMap,
    uEarth,
    Layer,
    ViewPort,
    StakeNum
) {

    function Bench(option) {
        var _this = this;
        option && _this.OptionToProperties(option);

        _this.startStakeNum = StakeNum.transform(_this["开始桩号"]);
        _this.stopStakeNum = StakeNum.transform(_this["结束桩号"]);

        _this.stakeNum = _this.startStakeNum;

        _this.title = _this["开始桩号"] + " > " + _this["结束桩号"] + " / " + _this["朝向"];

        _this.searchKey = _this["开始桩号"] + _this["朝向"];
        _this.sortKey = _this.startStakeNum.distance;

        if (_this.position) {

            _this.layer = new Layer({
                "app"     : _this.app,
                "viewport": new ViewPort({
                    "center": _this.position
                })
            });

            _this.marker = new uMap.Entity({
                objectOption: {
                    position : _this.layer.viewport.center.cartesian,
                    billboard: new uMap.BillboardGraphic({
                        objectOption: {
                            image                   : _this.app.icons.getIconMarker(_this.icon),
                            verticalOrigin          : "BOTTOM",
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                    }),
                    label    : new uMap.LabelGraphic({
                        objectOption: {
                            text                    : _this["名称"],
                            verticalOrigin          : "TOP",
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                    })
                }
            });
            _this.layer.dataSources.entities.add(_this.marker.object);
        }


    }

    var _class = Bench;

    mhjs.OptionToPropertiesInterface(_class);
    mhjs.EventInterface(_class);

    Object.defineProperties(_class.prototype, {
        "open"  : {
            value: function () {
                if (!this.isOpened) {
                    this.layer && this.layer.open();
                    this.isOpened = true;
                    this.trigger("open");
                }
            }
        },
        "close" : {
            value: function () {
                if (this.isOpened) {
                    this.layer && this.layer.close();
                    this.isOpened = false;
                    this.trigger("close");
                }
            }
        },
        "toggle": {
            value: function () {
                if (this.isOpened) {
                    this.close();
                } else {
                    this.open();
                }
            }
        },
        "active": {
            value: function (isActive) {
                var _this = this;

                isActive = (isActive === undefined) || Boolean(isActive);
                _this.isActive = _this.isActive === undefined ? false : _this.isActive;

                if (isActive !== _this.isActive) {

                    if (isActive) {
                        _this.marker.label.fillColor = new uMap.Color(["#ff0"]);
                        _this.marker.billboard.image = _this.app.icons.getIconMarker(_this.icon, true);
                        _this.trigger("active");
                    } else {
                        _this.marker.label.fillColor = new uMap.Color(["#fff"]);
                        _this.marker.billboard.image = _this.app.icons.getIconMarker(_this.icon);
                        _this.trigger("unActive");
                    }

                    _this.isActive = isActive;

                }

            }
        }
    });

    return _class;

});